﻿namespace XUCore.WeChat.Enterprise.Net.ServerMessages.From
{
    using Newtonsoft.Json;
    using System.Collections.Generic;
    using System.Xml.Serialization;
    using XUCore.WeChat.Net.ServerMessages.From;

    /// <summary>
    /// 添加企业客户事件
    /// </summary>
    [XmlRoot("xml")]
    public class FromChangeExternalContactAddExternalContactEvent : FromEventBase
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="FromChangeExternalContactAddExternalContactEvent"/> class.
        /// </summary>
        public FromChangeExternalContactAddExternalContactEvent()
        {
            Event = FromEventTypes.change_external_contact;
            ChangeType = ChangeExternalContacChangeType.add_external_contact;
        }

        /// <summary>
        /// 操作类型  
        /// </summary>
        public ChangeExternalContacChangeType ChangeType { get; set; }

        /// <summary>
        /// 企业服务人员的UserID
        /// </summary>
        [XmlElement("UserID")]
        public string UserID { get; set; }

        /// <summary>
        /// 外部联系人的userid，注意不是企业成员的账号
        /// </summary>
        [XmlElement("ExternalUserID")]
        public string ExternalUserID { get; set; }

        /// <summary>
        /// add才会出现---添加此用户的「联系我」方式配置的state参数，或在获客链接中指定的customer_channel参数，可用于识别添加此用户的渠道
        /// </summary>
        [XmlElement("State")]
        public string State { get; set; }

        /// <summary>
        /// add才会出现---欢迎语code，可用于发送欢迎语
        /// </summary>
        [XmlElement("WelcomeCode")]
        public string WelcomeCode { get; set; }
    }

    /// <summary>
    /// 编辑企业客户事件
    /// </summary>
    [XmlRoot("xml")]
    public class FromChangeExternalContactEditExternalContactEvent : FromEventBase
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="FromChangeExternalContactEditExternalContactEvent"/> class.
        /// </summary>
        public FromChangeExternalContactEditExternalContactEvent()
        {
            Event = FromEventTypes.change_external_contact;
            ChangeType = ChangeExternalContacChangeType.edit_external_contact;
        }

        /// <summary>
        /// 操作类型  
        /// </summary>
        public ChangeExternalContacChangeType ChangeType { get; set; }

        /// <summary>
        /// 企业服务人员的UserID
        /// </summary>
        [XmlElement("UserID")]
        public string UserID { get; set; }

        /// <summary>
        /// 外部联系人的userid，注意不是企业成员的账号
        /// </summary>
        [XmlElement("ExternalUserID")]
        public string ExternalUserID { get; set; }
    }

    /// <summary>
    /// 外部联系人免验证添加成员事件
    /// </summary>
    [XmlRoot("xml")]
    public class FromChangeExternalContactAddHalfExternalContactEvent : FromEventBase
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="FromChangeExternalContactAddHalfExternalContactEvent"/> class.
        /// </summary>
        public FromChangeExternalContactAddHalfExternalContactEvent()
        {
            Event = FromEventTypes.change_external_contact;
            ChangeType = ChangeExternalContacChangeType.add_half_external_contact;
        }

        /// <summary>
        /// 操作类型  
        /// </summary>
        public ChangeExternalContacChangeType ChangeType { get; set; }

        /// <summary>
        /// 企业服务人员的UserID
        /// </summary>
        [XmlElement("UserID")]
        public string UserID { get; set; }

        /// <summary>
        /// 外部联系人的userid，注意不是企业成员的账号
        /// </summary>
        [XmlElement("ExternalUserID")]
        public string ExternalUserID { get; set; }

        /// <summary>
        /// 添加此用户的「联系我」方式配置的state参数，或在获客链接中指定的customer_channel参数，可用于识别添加此用户的渠道
        /// </summary>
        [XmlElement("State")]
        public string State { get; set; }

        /// <summary>
        /// 欢迎语code，可用于发送欢迎语
        /// </summary>
        [XmlElement("WelcomeCode")]
        public string WelcomeCode { get; set; }
    }

    /// <summary>
    /// 删除跟进成员事件
    /// </summary>
    [XmlRoot("xml")]
    public class FromChangeExternalContactDelFollowUserEvent : FromEventBase
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="FromChangeExternalContactDelFollowUserEvent"/> class.
        /// </summary>
        public FromChangeExternalContactDelFollowUserEvent()
        {
            Event = FromEventTypes.change_external_contact;
            ChangeType = ChangeExternalContacChangeType.del_follow_user;
        }

        /// <summary>
        /// 操作类型  
        /// </summary>
        public ChangeExternalContacChangeType ChangeType { get; set; }

        /// <summary>
        /// 企业服务人员的UserID
        /// </summary>
        [XmlElement("UserID")]
        public string UserID { get; set; }

        /// <summary>
        /// 外部联系人的userid，注意不是企业成员的账号
        /// </summary>
        [XmlElement("ExternalUserID")]
        public string ExternalUserID { get; set; }
    }

    /// <summary>
    /// 删除企业客户事件
    /// </summary>
    [XmlRoot("xml")]
    public class FromChangeExternalContactDelExternalContactEvent : FromEventBase
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="FromChangeExternalContactDelExternalContactEvent"/> class.
        /// </summary>
        public FromChangeExternalContactDelExternalContactEvent()
        {
            Event = FromEventTypes.change_external_contact;
            ChangeType = ChangeExternalContacChangeType.del_external_contact;
        }

        /// <summary>
        /// 操作类型  
        /// </summary>
        public ChangeExternalContacChangeType ChangeType { get; set; }

        /// <summary>
        /// 企业服务人员的UserID
        /// </summary>
        [XmlElement("UserID")]
        public string UserID { get; set; }

        /// <summary>
        /// 外部联系人的userid，注意不是企业成员的账号
        /// </summary>
        [XmlElement("ExternalUserID")]
        public string ExternalUserID { get; set; }

        /// <summary>
        /// 删除客户的操作来源，DELETE_BY_TRANSFER表示此客户是因在职继承自动被转接成员删除
        /// </summary>
        [XmlElement("Source")]
        public string Source { get; set; }
    }

    /// <summary>
    /// 客户接替失败事件
    /// </summary>
    [XmlRoot("xml")]
    public class FromChangeExternalContactTransferFailEvent : FromEventBase
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="FromChangeExternalContactTransferFailEvent"/> class.
        /// </summary>
        public FromChangeExternalContactTransferFailEvent()
        {
            Event = FromEventTypes.change_external_contact;
            ChangeType = ChangeExternalContacChangeType.transfer_fail;
        }

        /// <summary>
        /// 操作类型  
        /// </summary>
        public ChangeExternalContacChangeType ChangeType { get; set; }

        /// <summary>
        /// 企业服务人员的UserID
        /// </summary>
        [XmlElement("UserID")]
        public string UserID { get; set; }

        /// <summary>
        /// 外部联系人的userid，注意不是企业成员的账号
        /// </summary>
        [XmlElement("ExternalUserID")]
        public string ExternalUserID { get; set; }

        /// <summary>
        /// 接替失败的原因, customer_refused-客户拒绝， customer_limit_exceed-接替成员的客户数达到上限
        /// </summary>
        [XmlElement("FailReason")]
        public string FailReason { get; set; }
    }

    public enum ChangeExternalContacChangeType
    {
        /// <summary>
        /// 添加企业客户事件
        /// </summary>
        add_external_contact = 1,
        /// <summary>
        /// 编辑企业客户事件
        /// </summary>
        edit_external_contact = 2,
        /// <summary>
        /// 外部联系人免验证添加成员事件
        /// </summary>
        add_half_external_contact = 3,
        /// <summary>
        /// 删除企业客户事件
        /// </summary>
        del_external_contact = 4,
        /// <summary>
        /// 删除跟进成员事件
        /// </summary>
        del_follow_user = 5,
        /// <summary>
        /// 客户接替失败事件
        /// </summary>
        transfer_fail = 6
    }
}
